import React, { Component } from 'react'
import { queryCategories } from '../../api/home';
import ArticleCate from '../../types/ArticleCate';
import View from './View';

interface IProps { }
interface IState {
    cates: ArticleCate[];
}
export default class HeaderController extends Component<IProps, IState> {
    constructor(props: IProps) {
        super(props);
        this.state = {
            cates: []
        }
    }

    async componentDidMount() {
        const cates: Array<ArticleCate> | null = await queryCategories();
        if (!!cates) {
            this.setState({
                cates
            })
        }
    }

    render() {
        return (
            <View cates={this.state.cates} />
        )
    }
}
